import router, { varRoutes, constantRoutes } from '@/router'

const state = {
  // 用来存放路由规则集合
  routes: [],
  // 员工页面按钮权限标识
  points: {
    pointUserUpdate: 'point-user-update',
    pointUserDelete: 'point-user-delete',
    pointUserEdit: 'point-user-edit',
    pointUserSetJob: 'point-user-job',
    // 权限页面的权限标识
    pointPermissionAdd: 'point-permission-add',
    pointPermissionDelete: 'point-permission-delete'
  }
}
const mutations = {
  filterRouter(state, roles) {
    // roles.menus 可以访问的路由模块,varRoutes 所有的动态路由集合
    console.log(varRoutes)
    // 根据后台返回标识在所有的动态路由中进行筛选
    const filterRouter = varRoutes.filter(item => roles.menus.includes(item.name))
    console.log(filterRouter)
    const router404 = { path: '*', redirect: '/404', hidden: true }
    // 动态添加路由规则
    router.addRoutes([...filterRouter, router404])
    // 将所有路由规则存储到vuex中
    state.routes = [...constantRoutes, ...filterRouter, router404]
  }
}
const actions = {}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
